From 5d1c53c6fd593de2360c1a2ae44ebf5fa3c5263b Mon Sep 17 00:00:00 2001
From: hjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 16 Jan 2018 11:22:01 +0000
Subject: [PATCH 9/9] x86: Disallow -mindirect-branch=/-mfunction-return= with
 -mcmodel=large

Since the thunk function may not be reachable in large code model,
-mcmodel=large is incompatible with -mindirect-branch=thunk,
-mindirect-branch=thunk-extern, -mfunction-return=thunk and
-mfunction-return=thunk-extern.  Issue an error when they are used with
-mcmodel=large.

gcc/

	Backport from mainline
	2018-01-14  H.J. Lu  <hongjiu.lu@intel.com>

	* config/i386/i386.c (ix86_set_indirect_branch_type): Disallow
	-mcmodel=large with -mindirect-branch=thunk,
	-mindirect-branch=thunk-extern, -mfunction-return=thunk and
	-mfunction-return=thunk-extern.
	* doc/invoke.texi: Document -mcmodel=large is incompatible with
	-mindirect-branch=thunk, -mindirect-branch=thunk-extern,
	-mfunction-return=thunk and -mfunction-return=thunk-extern.

gcc/testsuite/

	Backport from mainline
	2018-01-14  H.J. Lu  <hongjiu.lu@intel.com>

	* gcc.target/i386/indirect-thunk-10.c: New test.
	* gcc.target/i386/indirect-thunk-8.c: Likewise.
	* gcc.target/i386/indirect-thunk-9.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-10.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-11.c: Likewise.
	* gcc.target/i386/indirect-thunk-attr-9.c: Likewise.
	* gcc.target/i386/ret-thunk-17.c: Likewise.
	* gcc.target/i386/ret-thunk-18.c: Likewise.
	* gcc.target/i386/ret-thunk-19.c: Likewise.
	* gcc.target/i386/ret-thunk-20.c: Likewise.
	* gcc.target/i386/ret-thunk-21.c: Likewise.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@256737 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog                                      | 13 +++++++++++
 gcc/config/i386/i386.c                             | 26 ++++++++++++++++++++++
 gcc/doc/invoke.texi                                | 11 +++++++++
 gcc/testsuite/ChangeLog                            | 17 ++++++++++++++
 gcc/testsuite/gcc.target/i386/indirect-thunk-10.c  |  7 ++++++
 gcc/testsuite/gcc.target/i386/indirect-thunk-8.c   |  7 ++++++
 gcc/testsuite/gcc.target/i386/indirect-thunk-9.c   |  7 ++++++
 .../gcc.target/i386/indirect-thunk-attr-10.c       |  9 ++++++++
 .../gcc.target/i386/indirect-thunk-attr-11.c       |  9 ++++++++
 .../gcc.target/i386/indirect-thunk-attr-9.c        |  9 ++++++++
 gcc/testsuite/gcc.target/i386/ret-thunk-17.c       |  7 ++++++
 gcc/testsuite/gcc.target/i386/ret-thunk-18.c       |  8 +++++++
 gcc/testsuite/gcc.target/i386/ret-thunk-19.c       |  8 +++++++
 gcc/testsuite/gcc.target/i386/ret-thunk-20.c       |  9 ++++++++
 gcc/testsuite/gcc.target/i386/ret-thunk-21.c       |  9 ++++++++
 15 files changed, 156 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-10.c
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-8.c
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-9.c
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-10.c
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-11.c
 create mode 100644 gcc/testsuite/gcc.target/i386/indirect-thunk-attr-9.c
 create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-17.c
 create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-18.c
 create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-19.c
 create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-20.c
 create mode 100644 gcc/testsuite/gcc.target/i386/ret-thunk-21.c

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1e572b1..6f3c344 100644
--- a/src/gcc/doc/invoke.texi
+++ b/src/gcc/doc/invoke.texi
@@ -25699,6 +25699,11 @@ to external call and return thunk provided in a separate object file.
 You can control this behavior for a specific function by using the
 function attribute @code{indirect_branch}.  @xref{Function Attributes}.
 
+Note that @option{-mcmodel=large} is incompatible with
+@option{-mindirect-branch=thunk} nor
+@option{-mindirect-branch=thunk-extern} since the thunk function may
+not be reachable in large code model.
+
 @item -mfunction-return=@var{choice}
 @opindex -mfunction-return
 Convert function return with @var{choice}.  The default is @samp{keep},
@@ -25710,6 +25715,12 @@ object file.  You can control this behavior for a specific function by
 using the function attribute @code{function_return}.
 @xref{Function Attributes}.
 
+Note that @option{-mcmodel=large} is incompatible with
+@option{-mfunction-return=thunk} nor
+@option{-mfunction-return=thunk-extern} since the thunk function may
+not be reachable in large code model.
+
+
 @item -mindirect-branch-register
 @opindex -mindirect-branch-register
 Force indirect call and jump via register.
